
JOGL-ES Chapter 2. Loading OBJ Models

From:
  Pro Java 6 3D Game Development 

  Dr. Andrew Davison
  Dept. of Computer Engineering
  Prince of Songkla University
  Hat Yai, Songkhla 90112, Thailand
  E-mail: ad@fivedots.coe.psu.ac.th

  Web Site for the book: http://fivedots.coe.psu.ac.th/~ad/jg2/


If you use this code, please mention my name, and include a link
to the book's Web site.

**NOTE**: this example is NOT in the hardcopy book printed by Apress.

Thanks,
  Andrew


============================
ViewerES

The canvas displays a floor, and OBJ models are loaded,
positioned, and scaled using instances of OBJShape.
The user can navigate around the scene using the navigational
keys.


ViewerES requires the Java Bindings for OpenGL ES (JSR 239) API which
is available in version 2.5. (or later) of the Java ME Wirelss Toolkit 
(WTK 2.5). It can be downloaded from 
http://java.sun.com/products/sjwtoolkit/

------
Files in the Download

ViewerES consists of:

1 Java file at the top-level:
  OBJShape.java

7 Java files in the src\ subdirectory:
  ViewerES.java, ViewerGameCanvas.java,
  KeyCamera.java, Camera.java,               
  Floor.java
  and
  HandModel.java, PenguinModel.java

2 image files in the res\ directory
  bigGrid.png, penguin.png


HandModel.java and PenguinModel.java are copies of OBJShape.java
with arrays and variables pasted in so they can display a hand and
a penguin. PenguinModel.java uses the penguin.png image as a texture.


------
Compilation and Execution (using WTK 2.5)

Create a new project called ViewerES, with the MIDlet
class name ViewerES.

In the "API Selection" window, select the radio box
for "Java Bindings for OpenGL ES (JSR 239)" which is
located in the "Additional APIs" section

Copy the Java files in src\ to WTK25\apps\ViewerES\src\ 

Copy the PNG files in res\ to WTK25\apps\ViewerES\res\

Build and run.

-----------
Using OBJShape.java

The output from ObjView (the Java 3D application) is stored
in examObj.txt in ObjView's directory. Copy all the text from 
examObj.txt into a *COPY* of OBJShape.java.

The code should be copied into the space between the comments:

  // ------------------ start model data --------------------------
  // PASTE in the contents of examObj.txt here



  // ------------------ end model data --------------------------

These occur at line 93 in OBJShape.java.


Rename the modified OBJShape.java file (e.g. to FooModel.java),
and change the class name (e.g. to FooModel). Move it into the
src\ directory with the other Java files.


Modify ViewerGameCanvas in three places:

1. Define the model variable as a global.
   e.g.
       private FooModel fooModel;

2. Create the model in createScenery():
   e.g.
       fooModel = new FooModel(gl, 1.5f, 0.5f, 2.3f, 3.0f);

   The arguments are its (x,y,z) position, and its scale factor.

3. Draw the model in drawSceneGL():
   e.g.
       fooModel.draw();

---------
Last updated: 27th April 2007
